const Koa = require('koa')
const views = require('koa-views')
const static = require('koa-static')
const koaBody = require('koa-body')
const Router = require('koa-router')
const fs = require('fs')
let Koas = new Koa()
let router = new Router()
Koas.use(views(__dirname + '/views'))
Koas.use(static(__dirname + '/static'))
router.get('/addnews', async ctx => {
    await ctx.render('addNews.html')
})
router.post('/postfile', ctx => {
    console.log(ctx.request.body);
    console.log(ctx.request.files);
    //转存文件，文件路径
    let fileurl = './uploads/' + filename
    let newObj = {
        ...ctx.request.body,
        fileurl,
    };
    if (!fs.existsSync('./data/data.json', JSON.stringify([newObj])))

})





Koas.use(router.routes())
Koas.listen(8787)